//
//  StatisticNetUnReachView.m
//  soosoa
//
//  Created by 雨辰科技 on 16/10/21.
//  Copyright © 2016年 liq. All rights reserved.
//

#import "StatisticNetUnReachView.h"
#import "CommonHeader.h"

@interface StatisticNetUnReachView ()

@property(nonatomic,strong)UIImageView *imageView;
@property(nonatomic,strong)UILabel *remindLab;
@property(nonatomic,strong)UIButton *reBtn;

@end

@implementation StatisticNetUnReachView

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self createMain];
    }
    return self;
}
-(void)createMain{
    self.backgroundColor = [UIColor whiteColor];
    _imageView= [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_not_network"]];
    _imageView.userInteractionEnabled  = YES;
    [self addSubview:_imageView];


    UILabel *lab = [UILabel new];
    lab.text = @"暂无网络，点击空白处重试";
    _remindLab = lab;
    lab.textColor = [UIColor jk_colorWithHexString:@"#999999"];
    lab.font = [UIFont systemFontOfSize:adaptWidth750(28)];
    [self addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self);
    }];
    
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lab.mas_top).offset(adaptWidth375(-18));
        make.centerX.mas_equalTo(self);
    }];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    _reBtn = btn;
    [btn setBackgroundImage:[UIImage imageNamed:@"not_network_bg"] forState:UIControlStateNormal];
    btn.titleEdgeInsets= UIEdgeInsetsMake(-adaptHeight1334(10), 0, 0, 0);
    [btn setTitle:@"重新加载" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:adaptFontSize(28)];
    [btn addTarget:self action:@selector(reload) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lab.mas_bottom).with.offset(adaptHeight1334(30));
        make.centerX.mas_equalTo(self);
        make.left.equalTo(self).offset((IMSCREEN_WIDTH-adaptWidth750(628))/2);
        make.height.mas_equalTo(adaptHeight1334(108));
    }];
    
    btn.hidden = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(reload)];
    [self addGestureRecognizer:tap];
}


-(void)reload
{
    if(self.reloadBlock)
        self.reloadBlock();
}

@end


@implementation PartUnnetView

- (instancetype)init{
    if(self=[super init]){
        [self configure];
    }
    return self;
}

- (void)configure{
    self.backgroundColor = [UIColor whiteColor];
    
    self.reloadBtn = [UIButton new];
    self.reloadBtn.layer.cornerRadius = 4;
    self.reloadBtn.layer.masksToBounds = YES;
    self.reloadBtn.titleLabel.font = KIMFontRegularSize(11.7);
    [self.reloadBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.reloadBtn.backgroundColor = [UIColor jk_colorWithHexString:@"#018AE5"];
    [self.reloadBtn setTitle:@"网络走丢了,点我重新加载" forState:UIControlStateNormal];
    [self.reloadBtn addTarget:self action:@selector(reloadAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.reloadBtn];
    
    [self.reloadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(adaptWidth750(180*2));
        make.height.mas_equalTo(adaptWidth750(24*2));
        make.center.equalTo(self);
    }];
}

- (void)reloadAction{
//    [self.reloadBtn startLoading];
    !self.reloadBlock?:self.reloadBlock();
}


@end


